import {deepClone} from '@/utils/arr' 
export default {
	state: {
		keepLiveRoute: [],
		routeKey: null,
		routeShow: true
	},
	mutations: {
		pushKeepLive(state, component){
			if(!state.keepLiveRoute.includes(component)){
				state.keepLiveRoute.push(component)
			}
		},
		removeKeepLive(state, component){
			//如果只是做splice操作组件并不会执行unmounted需要做赋值操作
			let arr = deepClone(state.keepLiveRoute)
			var index = arr.indexOf(component);
			if(index !== -1){
				arr.splice(index, 1);
			}
			state.keepLiveRoute = arr
		},
		clearKeepLive(state){
			state.keepLiveRoute = []
		},
		setRouteKey(state, key){
			state.routeKey = key
		},
		setRouteShow(state, key){
			state.routeShow = key
		}
	},
	actions: {
		setRouteKey({ commit }, key) {
			commit('setRouteKey', key);
		}
	}
}
